#!/bin/bash

PLIST_PATH="$HOME/Library/LaunchAgents/com.whatnot.capture.printhelper.plist"
SUPPORT_DIR="$HOME/Library/Application Support/WhatnotPrintHelper"

ANSWER=$(osascript <<'APPLESCRIPT'
display dialog "Remove Whatnot auto-print from this Mac?" buttons {"Cancel", "Uninstall"} default button "Uninstall" with icon caution with title "Uninstall Whatnot Printing"
if button returned of result is "Cancel" then
  return "CANCEL"
end if
return "OK"
APPLESCRIPT
)

if [ "$ANSWER" = "CANCEL" ]; then
  exit 0
fi

launchctl bootout "gui/$(id -u)" "$PLIST_PATH" 2>/dev/null || true
rm -f "$PLIST_PATH"
rm -rf "$SUPPORT_DIR"

osascript -e 'display alert "Uninstalled" message "Whatnot print helper was removed." buttons {"OK"} default button "OK"'
